package cn.icanci.loopstack.bic.biz.dts.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.bic.biz.dts.DTS;
import cn.icanci.loopstack.bic.biz.dts.GraphDtsService;
import cn.icanci.loopstack.bic.biz.service.EdgeStyleService;
import cn.icanci.loopstack.bic.biz.service.NodeStyleService;
import cn.icanci.loopstack.bic.biz.utils.TemplateFileUtils;
import cn.icanci.loopstack.bic.common.model.base.EdgeStyleVO;
import cn.icanci.loopstack.bic.common.model.base.NodeStyleVO;
import cn.icanci.loopstack.bic.common.model.base.SystemVO;

/**
 * @author icanci
 * @since 1.0 Created in 2023/09/20 19:47
 */
@Service
@DTS(SystemVO.class)
public class SystemDtsServiceImpl implements GraphDtsService<SystemVO> {
    @Resource
    private EdgeStyleService    edgeStyleService;
    @Resource
    private NodeStyleService    nodeStyleService;

    private static final String DEFAULT_NAME = "系统默认";
    private static final String DEFAULT_KEY  = "DEFAULT_KEY";

    @Override
    public void dtsUnitViewTree(SystemVO system) {
        // 插入默认边样式
        edgeStyleService.save(buildEdge(system));
        // 插入默认节点样式
        nodeStyleService.save(buildNodeStyle(system.getUuid()));
    }

    private EdgeStyleVO buildEdge(SystemVO system) {
        EdgeStyleVO edge = new EdgeStyleVO();
        edge.setSystemUuid(system.getUuid());
        edge.setEdgeStyleName(DEFAULT_NAME);
        edge.setEdgeStyleKey(DEFAULT_KEY);
        edge.setEdgeStyle(TemplateFileUtils.queryDefaultEdgeStyleTemplate());
        return edge;
    }

    private NodeStyleVO buildNodeStyle(String systemUuid) {
        NodeStyleVO nodeStyle = new NodeStyleVO();
        nodeStyle.setSystemUuid(systemUuid);
        nodeStyle.setNodeStyleName(DEFAULT_NAME);
        nodeStyle.setNodeStyleKey(DEFAULT_KEY);
        nodeStyle.setNodeStyle(TemplateFileUtils.queryDefaultNodeStyleTemplate());
        return nodeStyle;
    }
}
